# -*- coding:utf-8 -*- 
import sys;
import urllib;
import urllib2;
import codecs;
import base64;
import re;

if(__name__=="__main__"):
#    response = urllib2.urlopen(url="http://192.168.0.1:8888/", data=None);
#    print response.read();
    
    m_argv = sys.argv;
    #m_argv=["a","-u","jiangfei","-p","15810546251"];
    if(len(m_argv)!=5):
        print "请输入-u 用户名 -p 密码";
    else:
        u = m_argv[2];
        p = m_argv[4];
        m_encoding8 = codecs.lookup("utf_8");
        
        m_encoding16 = codecs.lookup("utf_16");
        
        m_str_up = u+"|"+p;
        
        #print m_str_up;
        
        m_bytes = m_encoding16.decode(m_str_up);
        
        m_bytes = m_encoding8.encode(m_bytes[0]);
        
        m_str = base64.encodestring(m_str_up);
        
        values = {};
        values["language"]="1";
        values["actionType"]="umlogin";
        values["userIpMac"]="";
        values["authorization"]=m_str;
        
        m_data = urllib.urlencode(values)    
        
        request = urllib2.Request("http://192.168.0.1:8888/",data=m_data);        
        
        #print request.get_full_url(),request.get_host(),request.get_method(),request.get_type();
        
        #request.add_data()
        
        response = urllib2.urlopen(request);
        
        m_str_return = response.read();
        
        #print m_str_return;
        
        m_regex_re = re.compile(r'[\s\S]*?<title>([\s\S]*?)</title>',re.IGNORECASE);
        
        m_match_mc = m_regex_re.match(m_str_return);
        
        m_str_re = m_match_mc.group(1);
        
        print m_str_re.decode("gb2312").encode("utf-8");
        
        pass
    